#include "data_global.h"

pthread_cond_t cond_camera;
pthread_cond_t cond_analysis;
pthread_cond_t cond_sqlite;
pthread_cond_t cond_uart_cmd;
pthread_cond_t cond_buzzer;

pthread_mutex_t mutex_refresh;
pthread_mutex_t mutex_analysis;
pthread_mutex_t mutex_transfer;
pthread_mutex_t mutex_sqlite;

extern void * pthread_refresh ();			
extern void * pthread_analysis();	
extern void * pthread_tranfer() ;
extern void * pthread_sqlite();


int main(int argc, char *argv[])
{
	pthread_t id_refresh;
	pthread_t id_analysis;
	pthread_t id_sqlite;
	pthread_t id_tranfer;
	
	pthread_mutex_init (&mutex_refresh, NULL);  
	pthread_mutex_init (&mutex_analysis, NULL);  
	pthread_mutex_init (&mutex_transfer, NULL);
	pthread_mutex_init (&mutex_sqlite, NULL);

	
	pthread_cond_init (&cond_camera,NULL);
	pthread_cond_init (&cond_analysis, NULL); 
	pthread_cond_init (&cond_sqlite, NULL); 
	pthread_cond_init (&cond_uart_cmd, NULL); 
	pthread_cond_init (&cond_buzzer, NULL); 
	
	get_queue_id();
	list_create();

	if(pthread_create(&id_refresh, NULL, pthread_refresh,NULL) < 0)
	{
		perror("pthread_create");
		exit(1);
	}
	if(pthread_create(&id_analysis, NULL, pthread_analysis,NULL) < 0)
	{
		perror("pthread_create");
		exit(1);
	}		
	if(pthread_create(&id_sqlite, NULL, pthread_sqlite,NULL) < 0)
	{
		perror("pthread_create");
		exit(1);
	}
	if(pthread_create(&id_tranfer, NULL, pthread_tranfer,NULL) < 0)
	{
		perror("pthread_create");
		exit(1);
	}
	
	pthread_join (id_tranfer, NULL);
	pthread_join (id_sqlite, NULL);
	pthread_join (id_refresh, NULL);
	pthread_join (id_analysis, NULL);
}
